import { ITlPos, IJtPos } from "./model";

export class Proto {
    cmdCode: number;
    name: string;

    constructor(cmdCode: number, name: string) {
        this.cmdCode = cmdCode;
        this.name = name;
    }
}

export const MoveJ = new Proto(201, "MoveJ");
export const MoveC = new Proto(202, "MoveC");
export const MoveL = new Proto(203, "MoveL");
export const RESETALLERROR = new Proto(107, "RESETALLERROR");
export const ActGripper = new Proto(227, "ActGripper");
export const MoveGripper = new Proto(228, "MoveGripper");
export const SetTPDStart = new Proto(315, "SetTPDStart");
export const SetWebTPDStop = new Proto(322, "SetWebTPDStop");
export const SetTPDDelete = new Proto(318, "SetTPDDelete");
export const MoveTPD = new Proto(217, "MoveTPD");

export function actGripperArgs(): string[] {
    return ["1", "1"];
}

export function moveGripper(
    pos: number,
    speed: number = 100,
    tor: number = 100,
    maxTime: number = 30 * 1000
): string[] {
    return [
        "1",
        pos.toString(), speed.toString(),
        tor.toString(), maxTime.toString()
    ];
}

export function moveJArgs(
    jt: IJtPos,
    tl: ITlPos,
    speed: number = 100, 
    acc: number = 180, 
    ovl: number = 100, 
    blandT: number = 0): string[] {
    
    return [
        jt.p1.toFixed(3),
        jt.p2.toFixed(3),
        jt.p3.toFixed(3),
        jt.p4.toFixed(3),
        jt.p5.toFixed(3),
        jt.p6.toFixed(3),

        tl.x.toFixed(3),
        tl.y.toFixed(3),
        tl.z.toFixed(3),
        tl.rx.toFixed(3),
        tl.ry.toFixed(3),
        tl.rz.toFixed(3),
        
        "0", "0",
        speed.toString(), acc.toString(), ovl.toString(),
        "0", "0", "0", "0",
        blandT.toString(), "0",
        "0", "0", "0", "0", "0", "0"
    ];
}

export function moveLArgs(
    jt: IJtPos,
    tl: ITlPos,
    speed: number = 100, 
    acc: number = 180, 
    ovl: number = 100, 
    blandT: number = 0): string[] {

    return [
        jt.p1.toFixed(3),
        jt.p2.toFixed(3),
        jt.p3.toFixed(3),
        jt.p4.toFixed(3),
        jt.p5.toFixed(3),
        jt.p6.toFixed(3),

        tl.x.toFixed(3),
        tl.y.toFixed(3),
        tl.z.toFixed(3),
        tl.rx.toFixed(3),
        tl.ry.toFixed(3),
        tl.rz.toFixed(3),

        "0", "0",
        speed.toString(), acc.toString(), ovl.toString(),
        blandT.toString(),
        "0", "0", "0", "0",
        "0", "0",
        "0", "0", "0", "0", "0", "0"
    ];
}

export function setTPDStartArgs(
    filename: string,
    msPeriod: number = 2,
): string[] {
    return [
        "1",
        `"${filename}"`,
        msPeriod.toString(),
        "0", "0"
    ];
}

export function setWebTPDStopArgs(
    filename: string,
    msPeriod: number = 2,
): string[] {
    return [
        "1",
        `"${filename}"`,
        msPeriod.toString(),
        "0", "0"
    ];
}

export function moveTPDArgs(
    filename: string,
    bland: number = 1,
    ovl: number = 200
): string[] {
    return [
        `"${filename}"`,
        bland.toString(),
        ovl.toString()
    ];
}

export function setTPDDeleteArgs(
    filename: string
): string[] {
    return [
        `"${filename}"`
    ];
}


